﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BKO.DataAccesss;
using BKO.DataAccesss.Repositories;
using BKO.Domain.Model;
using BKO.Domain.Services;

namespace BKO.Services
{
	public class FilialService : BaseService<IFilial>, IFilialService
	{
		public FilialService(string connectionString)
			: base(new BaseRepository<IFilial, FilialEntity>(BKODataContextSingletone.GetInstance(connectionString)))
		{
		}

		public List<IFilial> GetAllByBranch(string branch, bool visible)
		{
			IQueryable<IFilial> query = Repository.GetAll();
			if (!string.IsNullOrWhiteSpace(branch))
			{
				query = query.Where(f => f.Name == branch);
			}

			if (!visible)
			{
				query = query.Where(f => f.ARHIV == 0);
			}
			query = query.OrderBy(f => f.Name);

			return query.ToList();
		}
	}
}
